package charts.skins
{
	import mx.skins.ProgrammaticSkin;
	import flash.geom.ColorTransform;
	import mx.utils.ColorUtil;
	
	/**
	 * A skin shaped like a cube with a single color.
	 * 
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 9
	 * @author Ivan Gong
	 */
	public class CubeSkin extends ProgrammaticSkin implements IProgrammaticSkin
	{
		
	//--------------------------------------
	//  Constructor
	//--------------------------------------
	
		/**
		 * Constructor.
		 */
		public function CubeSkin()
		{
			super();
		}
		
	//--------------------------------------
	//  Properties
	//--------------------------------------
		
		/**
		 * @private
		 * Storage for the fillColor property.
		 */
		private var _fillColor:uint = 0x0000ff;
		
		/**
		 * @copy com.yahoo.charts.skins.IProgrammaticSkin#fillColor
		 */
		public function get fillColor():uint
		{
			return this._fillColor;
		}
		
		/**
		 * @private
		 */
		public function set fillColor(value:uint):void
		{
			if(this._fillColor != value)
			{
				this._fillColor = value;
				this.invalidateDisplayList();
				this.invalidateProperties();
			}
		}
		
	//--------------------------------------
	//  Protected Methods
	//--------------------------------------
	
		/**
		 * @private
		 */
	 	override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			this.graphics.clear();
			
			if(this.width == 0 || this.height == 0) return;
			
			// var angle:Number = Math.PI/8;
			// var h1:Number = Math.sin(angle);
			
			if(getStyle("fillColor"))
			{
				_fillColor = getStyle("fillColor");
			}
			
			var h1:Number = height/3;
			var w1:Number = width/3;
			
			var startX:Number = 0;
			var startY:Number = h1;
			var w:Number = width - w1;
			var h:Number = height - h1;
			//graphics.lineStyle(1, 0xff0000, 0.5);
			graphics.lineStyle(0, 0, 0);
			
			// front
			graphics.beginFill(_fillColor, 1);
			graphics.drawRect(startX,startY,w,h);
			graphics.endFill();
			
			// top
			graphics.beginFill(ColorUtil.adjustBrightness(_fillColor,-100), 1);
			graphics.moveTo(0,h1);
			graphics.lineTo(w1,0);
			graphics.lineTo(width,0);
			graphics.lineTo(width-w1,h1);
			graphics.lineTo(0,h1);
			graphics.endFill();
			
			// right
			graphics.beginFill(ColorUtil.adjustBrightness(_fillColor,-50), 1);
			graphics.moveTo(width,0)
			graphics.lineTo(width,height-h1);
			graphics.lineTo(width-w1,height);
			graphics.lineTo(width-w1,h1);
			graphics.lineTo(width,0);
			
			graphics.endFill();
			
			var value:Number = -50;
			//this.transform.colorTransform = new ColorTransform(1.0, 1.0, 1.0, this.alpha, value, value, value, 0);
			
		}
	}
}